package com.briup.mt.service.impl;

import com.briup.mt.bean.Module;
import com.briup.mt.bean.ModuleExample;
import com.briup.mt.dao.ModuleMapper;
import com.briup.mt.service.IGreenHouseModuleService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author yxy
 * @version 1.0
 * @date 2020/12/16 22:27
 */
@Service
public class GreenHouseModuleServiceImpl implements IGreenHouseModuleService {
    @Resource
    private ModuleMapper moduleMapper;

    @Override
    public List<Module> query(String name){
        ModuleExample example =new ModuleExample();
        if (!StringUtils.isEmpty(name)){
            example.createCriteria().andNameLike("%" +name+ "%");
        }
        return moduleMapper.selectByExample(example);
    }


    @Override
    public void saveOrUpdate(Module module){
        if (module.getId() == null) {
            moduleMapper.insert(module);
        }else {
            moduleMapper.updateByPrimaryKey(module);
        }

    }
    @Override
    public void deleteById(long id) {
        moduleMapper.deleteByPrimaryKey(id);
    }
}
